import React, {useEffect,useState} from 'react';
import {connect} from 'react-redux';
import {Button, Form, Input, message} from 'antd';
import {post} from "../../../utils";
import {mUrl} from "../../../config";

const Page = (props) => {
    const [form] = Form.useForm();
    const [loading, setLoading] = useState(false);
    
    useEffect(() => {
        form.setFieldsValue({
            agreementcontent: ''
        });
    }, []);


    const onFinish = (value) => {
        value.token = 1;
        value.agreementtype = 2;
        post(mUrl.addMessAgreement, value).then((res)=>{
            console.log(res);
            if(res.state === 1) {
                message.success('发布成功');
            }
        });
    };

    return (
        <div style={{padding: 14, background: '#fff', minHeight: 360}}>
            <label><p>协议管理 / 发布供货协议</p></label>
            <Form form={form} onFinish={onFinish}>
                <Form.Item name={"agreementcontent"}
                           labelCol={{span: 3}}
                           rules={[{required: true, message: '请输入详情'}]}
                           style={{marginBottom: 15}}>
                    <Input.TextArea rows={10} placeholder={'请输入'}/>
                </Form.Item>
                <Form.Item style={{marginTop: 10, textAlign: 'center'}}>
                    <Button
                        loading={loading} htmlType="submit" type={'primary'}
                    >发布</Button>
                </Form.Item>
            </Form>
        </div>
    );
};


export default connect()(Page);